

#include "atomic_op_namespace.h"

#include <sys/atomic.h>

uint8_t
atomic_swap_8(volatile uint8_t *addr, uint8_t new)
	asm("__sync_lock_test_and_set_1");

uint8_t
atomic_swap_8(volatile uint8_t *addr, uint8_t new)
{
	uint8_t old;

	do {
		old = *addr;
	} while (atomic_cas_8(addr, old, new) != old);

	return old;
}

crt_alias(__atomic_exchange_1,__sync_lock_test_and_set_1)
